package com.baijia.authentication.principal.resolver;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.principal.Credentials;
import com.baijia.authentication.principal.credentials.PassportCredentials;

import com.google.common.collect.Maps;

import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by dudu on 16/4/26.
 */
@Component
public class PassportPrincipalResolver extends AccountTypeCredentialsToPrincipalResolver {
    @Override
    protected String extractPrincipalId(Credentials credentials) {
        final PassportCredentials passportCredentials = (PassportCredentials) credentials;
        return passportCredentials.getUsername();
    }

    @Override
    protected Map<String, Object> generateAttributes(Credentials credentials) {
        return Maps.newHashMap();
    }

    @Override
    public int getAccountType() {
        return AccountType.PASSPORT.getCode();
    }

    @Override
    public boolean supports(Credentials credentials) {
        return credentials instanceof PassportCredentials;
    }
}
